<%@include file="template/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || Manage lesson</title>
        ${stylesheet}
        ${jquery}
        ${jsdropdown}
        <script type="text/javascript">
            
            window.onload = function () { 
                if (document.getElementById('islive').checked){
                    var obj = document.getElementById('livelesson');
                    obj.style.visibility = "visible";
                }
            }
            
            $(document).ready(function(){
                document.getElementById('livelesson').style.visibility="hidden";
            });
            var obj = document.getElementById('livelesson');
            obj.style.visibility = "hidden";
            function showMe(id) { 
                var obj = document.getElementById(id);
                if (obj.style.visibility=="hidden") {
                    obj.style.visibility = "visible";
                } else {
                    obj.style.visibility = "hidden";
                }
            }
        </script>
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content">
                <h1>Manage lessons</h1>
                <h3>
                    <c:choose>
                        <c:when test="${Lessonedit!=null}">Edit</c:when>
                        <c:otherwise>Add</c:otherwise>
                    </c:choose>lesson
                </h3>
                <c:choose>
                    <c:when test="${Lessonedit==null}">                        
                        <form action="ManageLesson" method="POST" name="Lessonadd">                    
                            <input type="hidden" name="formoption" value="Lessonadd"/>
                        </c:when>
                        <c:otherwise>
                            <form action="ManageLesson" method="POST" name="Lessonedit">                    
                                <input type="hidden" name="formoption" value="Lessonedit"/>
                            </c:otherwise>                    
                        </c:choose>
                        <label for="name">Name</label> <input type="text" name="name" id="name" value="${Lessonedit.name}"/>
                        </br>
                        <c:set var="courseid" value='<%=request.getParameter("courseid")%>' />
                        <c:if test="${courseid!=null}">
                            <input type="hidden" name="courseid" value="<%=request.getParameter("courseid")%>"/>                            
                        </c:if>
                        <c:if test="${courseid==null}">                            

                            <label for="course">Course</label>
                            <div class="relative">
                                <select class="select" name="course" id="course">
                                    <option value="0">Choose course</option>
                                    <c:forEach items="${allcourses}" var="course">
                                        <option value="${course.id}" <c:if test="${course.id == Lessonedit.course.id}">selected</c:if>>${course.name}</option>
                                    </c:forEach>
                                </select>
                                <span class="pointer"></span>
                            </div>
                            <div class="clear margin-bottom-5"></div>
                        </c:if>
                        <label for="description">Description</label> <textarea name="description" id="description">${Lessonedit.description}</textarea>
                        </br>
                        <label for="tab"></label> <input type="checkbox" value="isfree" name="isfree" <c:if test="${Lessonedit.freeLesson}">checked</c:if> /> Free lesson.
                        </br>
                        <label for="tab"></label> <input type="checkbox" id="islive" value="islive" name="islive" onclick="showMe('livelesson');" <c:if test="${Lessonedit.liveLesson}">checked</c:if>/> Live lesson.
                        </br>
                        <div id="livelesson">
                            <label for="name">Time and date: </label> 

                            <select name="hour">
                                <c:choose><c:when test="${editDate}"><option value="${hour}">${hour}</option></c:when><c:otherwise><option value="-">Hours</option></c:otherwise></c:choose>
                                <% for (int i = 0; i < 10; i++) {
                                        out.print("<option value=\"" + i + "\">0" + i + "</option>");
                                    }%>
                                <% for (int i = 10; i <= 23; i++) {
                                        out.print("<option value=\"" + i + "\">" + i + "</option>");
                                    }%>
                            </select>
                            :
                            <select name="minute">
                                 <c:choose><c:when test="${editDate}"><option value="${minute}">${minute}</option></c:when><c:otherwise><option value="-">Minute</option></c:otherwise></c:choose>
                                <% for (int i = 0; i < 10; i++) {
                                        out.print("<option value=\"" + i + "\">0" + i + "</option>");
                                    }%>
                                <% for (int i = 10; i <= 59; i++) {
                                        out.print("<option value=\"" + i + "\">" + i + "</option>");
                                    }%>
                            </select>

                            <select name="day">
                                 <c:choose><c:when test="${editDate}"><option value="${day}">${day}</option></c:when><c:otherwise><option value="-">Day</option></c:otherwise></c:choose>
                                <% for (int i = 1; i < 10; i++) {
                                        out.print("<option value=\"" + i + "\">0" + i + "</option>");
                                    }%>
                                <% for (int i = 10; i < 32; i++) {
                                        out.print("<option value=\"" + i + "\"> " + i + "</option>");
                                    }%>
                            </select>

                            <select name="month">
                              <c:choose><c:when test="${editDate}"><option value="1">January</option></c:when><c:otherwise><option value="-">Month</option></c:otherwise></c:choose>
                                <option value="1">January</option>
                                <option value="2">Febuary</option>
                                <option value="3">March</option>
                                <option value="4">April</option>
                                <option value="5">May</option>
                                <option value="6">June</option>
                                <option value="7">July</option>
                                <option value="8">August</option>
                                <option value="9">September</option>
                                <option value="10">October</option>
                                <option value="11">November</option>
                                <option value="12">December</option>
                            </select>


                            <select name="year">
                                <c:choose><c:when test="${editDate}"><option value="2013">2013</option></c:when><c:otherwise><option value="-">Year</option></c:otherwise></c:choose>
                                <% for (int i = 2013; i <= 2016; i++) {
                                        out.print("<option value=\"" + i + "\">" + i + "</option>");
                                    }%>
                            </select>
                            </br>
                            <label for="name">Justintv account:</label> <input type="text" name="embedStream" value="${livelesson.embedStream}"/>
                        </div>
                        </br>
                        <input type="hidden" name="Lessonid" value="${Lessonedit.id}"/>
                        <label>&nbsp;</label> <input type="submit" value="Save lesson"/>
                    </form>
            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>